package com.ruoyi.web.controller.gatewayManagement;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.MqttConfig;
import com.ruoyi.system.service.IMqttConfigService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * MQTT配置信息Controller
 * 
 * @author LGD
 * @date 2025-07-18
 */
@RestController
@RequestMapping("/gatewayManagement/MQTTconfig")
public class MqttConfigController extends BaseController
{
    @Autowired
    private IMqttConfigService mqttConfigService;

    /**
     * 查询MQTT配置信息列表
     */
    @PreAuthorize("@ss.hasPermi('gatewayManagement:MQTTconfig:list')")
    @GetMapping("/list")
    public TableDataInfo list(MqttConfig mqttConfig)
    {
        startPage();
        List<MqttConfig> list = mqttConfigService.selectMqttConfigList(mqttConfig);
        return getDataTable(list);
    }

    /**
     * 导出MQTT配置信息列表
     */
    @PreAuthorize("@ss.hasPermi('gatewayManagement:MQTTconfig:export')")
    @Log(title = "MQTT配置信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MqttConfig mqttConfig)
    {
        List<MqttConfig> list = mqttConfigService.selectMqttConfigList(mqttConfig);
        ExcelUtil<MqttConfig> util = new ExcelUtil<MqttConfig>(MqttConfig.class);
        util.exportExcel(response, list, "MQTT配置信息数据");
    }

    /**
     * 获取MQTT配置信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('gatewayManagement:MQTTconfig:query')")
    @GetMapping(value = "/{configId}")
    public AjaxResult getInfo(@PathVariable("configId") Long configId)
    {
        return success(mqttConfigService.selectMqttConfigByConfigId(configId));
    }

    /**
     * 新增MQTT配置信息
     */
//    @PreAuthorize("@ss.hasPermi('gatewayManagement:MQTTconfig:add')")
//    @Log(title = "MQTT配置信息", businessType = BusinessType.INSERT)
//    @PostMapping
//    public AjaxResult add(@RequestBody MqttConfig mqttConfig)
//    {
//        return toAjax(mqttConfigService.insertMqttConfig(mqttConfig));
//    }

    /**
     * 修改MQTT配置信息
     */
    @PreAuthorize("@ss.hasPermi('gatewayManagement:MQTTconfig:edit')")
    @Log(title = "MQTT配置信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MqttConfig mqttConfig)
    {
        return toAjax(mqttConfigService.updateMqttConfig(mqttConfig));
    }

    /**
     * 删除MQTT配置信息
     */
    @PreAuthorize("@ss.hasPermi('gatewayManagement:MQTTconfig:remove')")
    @Log(title = "MQTT配置信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{configIds}")
    public AjaxResult remove(@PathVariable Long[] configIds)
    {
        return toAjax(mqttConfigService.deleteMqttConfigByConfigIds(configIds));
    }
}
